package com.pet_service.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pet_service.entity.PetCategory;
import com.pet_service.mapper.PetCategoryMapper;
import com.pet_service.service.PetCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 邹全伸
* @description 针对表【pet_category(宠物类别表)】的数据库操作Service实现
* @createDate 2025-09-20 09:18:18
*/
@Service
@Slf4j
public class PetCategoryServiceImpl extends ServiceImpl<PetCategoryMapper, PetCategory>
    implements PetCategoryService{

    @Override
    public List<PetCategory> getRootCategories() {
        log.info("开始查询根分类（匹配 parent_id 为 NULL 或 0 + is_deleted = 0）...");
        List<PetCategory> result = lambdaQuery()
                .or().isNull(PetCategory::getParent_id) // 匹配 parent_id IS NULL
                .or().eq(PetCategory::getParent_id, 0)  // 匹配 parent_id = 0
                .eq(PetCategory::getIs_deleted, 0)
                .list();
        log.info("查询到 {} 条根分类", result.size());
        return result;
    }

    @Override
    public List<PetCategory> getChildCategories(Integer parent_id) {
        return lambdaQuery().eq(PetCategory::getParent_id, parent_id).list();
    }
}




